home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 151-175 / scopedisk165 / cliscreen / cliscreen.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  8KB  |  257 lines

  1. /*
  2.         This is a very very simple program that just opens a one-bitplane
  3.     screen to run your CLIs on.  This is useful for folks who are
  4.     using WorkBench 2.0 and have a 8- or 16-color WorkBench screen, but 
  5.     hate the scrolling and update speed when they use the CLI or Shell.
  6.     
  7.         It is easily solved by opening another screen and telling Intuition
  8.     that it is a WorkBench type screen.  Then when you pop open a CLI or
  9.     other WorkBench application, if this screen is in front of the "real"
  10.     WorkBench, the CLI or application will open on it.
  11.     
  12.         The default screen used is 640 X 400 with white text on a black 
  13.     background.  However, you may force it to be any size you so desire
  14.     by specifying the following parameters on the command line:
  15.     
  16.         -w#        Width desired.
  17.         
  18.         -h#        Height desired.
  19.         
  20.         -b#        Background color, specified as three hex digits. (RGB)
  21.         
  22.         -t#        Text color, specified as three hex digits. (RGB)
  23.         
  24.         These parameters may appear in any order, and are not case
  25.     sensitive.  So, if, for example, you wanted a medium resolution screen
  26.     with yellow text on a blue background, you would enter
  27.     
  28.             cliscreen -w640 -h200 -b00F -tFF0
  29.         
  30.         All screen sizes are supported, except the new screen modes in
  31.     WorkBench 2.0 (productivity, super-hires, etc.)  (working on it). 
  32.     This program will run fine from    1.2 or 1.3, as well as 2.0.
  33.     
  34.         This source was written using SAS/C for the Amiga version 5.10.
  35.     It should be linked with cback.o in order to allow it to detach from
  36.     the CLI it was run from.  I should think it would be trivial to port 
  37.     to other compilers, since this is pretty trivial code, really.  If 
  38.     you have a PAL machine, you'll need to adjust the values in the 
  39.     ReadArgs() routine to reflect the appropriate PAL sizes.
  40.         This source code is completely public domain.  You can do whatever
  41.     your heart desires with it.  But if you write something mean and nasty
  42.     with it, take my name off it first...
  43.     
  44.         Enjoy.
  45.         
  46.                 -- Robert Kesterson
  47. */
  48.  
  49. #include <ios1.h>            /* for Lattice stderr thing */
  50. #include <exec/types.h>
  51. #include <libraries/dos.h>
  52. #include <proto/dos.h>
  53. #include <intuition/intuition.h>
  54. #include <ctype.h>
  55. #include <stdlib.h>
  56.  
  57.  
  58.  
  59. /* 
  60.     These variables are needed for cback.o to work the way it needs to.
  61.     If you're porting to another compiler, you'll probably want to pay
  62.     close attention to this part.
  63. */
  64.  
  65. LONG _stack = 4000L;            /* may not even need that much     */
  66. char *_procname = "CLIScreen";    /* task name                    */
  67. LONG _priority = 0L;            /* will be asleep anyway        */
  68. LONG _BackGroundIO = 0L;        /* not planning on any            */
  69.  
  70. extern struct UFB _ufbs[];        /* also for stderr thing with Lattice */
  71.  
  72. /* Then these are just normal stuff */
  73.  
  74. struct TextAttr topazfont = { "topaz.font", 8, FS_NORMAL, FPB_ROMFONT };
  75.  
  76. struct NewScreen cli_screen =
  77.     {
  78.         0,0,640,400,1,            /* left top wide high deep         */
  79.         -1,-1,                    /* detail & block pens             */
  80.         NULL,                    /* flags (fill in later)        */
  81.         WBENCHSCREEN,            /* screen type                     */
  82.         &topazfont,                /* font                         */
  83.         "One-Plane CLI Screen",    /* title                         */
  84.         NULL,                    /* gadgets (none)                 */
  85.         NULL,                    /* no custom bitmap             */
  86.     };
  87.  
  88. struct NewWindow close_window =
  89.     {
  90.         0,0,150,11,                /* left top wide high             */
  91.         -1, -1,                    /* detail and block pens         */
  92.         CLOSEWINDOW,            /* IDCMP flags                     */
  93.         WINDOWCLOSE|WINDOWDRAG|SMART_REFRESH,    /* other flags     */
  94.         NULL,                    /* no gadgets                     */
  95.         NULL,                    /* no checkmark                 */
  96.         "Close to Exit",        /* title (message, actually)    */
  97.         NULL,                    /* screen pointer - fill below     */
  98.         NULL,                    /* no superbitmap                 */
  99.         0,0,0,0,                /* no resizing this one         */
  100.         WBENCHSCREEN
  101.     };
  102.  
  103. struct IntuitionBase *IntuitionBase = NULL;
  104. struct GfxBase *GfxBase = NULL;
  105.  
  106. struct Screen *screen = NULL;
  107. struct Window *window = NULL;
  108. struct IntuiMessage *msg = NULL;
  109.  
  110. SHORT wide = 640;                /* got to watch those short wides...     */
  111. SHORT high = 400;                
  112. UWORD color0 = 0x0000;            /* default colors for screen            */
  113. UWORD color1 = 0x0FFF;
  114.  
  115.  
  116. void ReadArgs(int argc,char **argv);
  117. BOOL OpenStuff(void);
  118. BOOL CloseStuff(void);
  119.  
  120.  
  121. /*     ********************************************************************
  122.                         the main() program...
  123.     
  124.     There is a really obscure piece of code in there about _ufbs[2].ufbfh
  125.     being closed.  All that is is closing the stderr output to allow the
  126.     shell to close.  Why cback doesn't do this, I haven't the faintest.
  127.        ******************************************************************** */
  128.  
  129.  
  130. void main(argc,argv)
  131. int argc;
  132. char **argv;
  133. {
  134.     if(!argc)                                /* CLI only, folks.        */
  135.         exit(20);
  136.     if(_ufbs[2].ufbfh)
  137.         Close(_ufbs[2].ufbfh);
  138.     ReadArgs(argc,argv);                    /* get parameters         */
  139.     if(!OpenStuff())                        /* set everything up     */
  140.         {
  141.             CloseStuff();
  142.             exit(10);
  143.         }
  144.     while(TRUE)                                /* hang around a while     */
  145.         {
  146.             while(msg = (struct IntuiMessage *)GetMsg(window->UserPort))    /* clear it again */
  147.                 ReplyMsg(msg);
  148.             WaitPort(window->UserPort);        /* wait for message     */
  149.             while(msg = (struct IntuiMessage *)GetMsg(window->UserPort))    /* clear it again */
  150.                 ReplyMsg(msg);
  151.     
  152.             if(CloseStuff())                /* wind it up             */
  153.                 break;
  154.             else
  155.                 DisplayBeep(screen);        /* can't leave just yet    */
  156.         }
  157.     exit(0);                                /* th-th-th-that's all, folks! */
  158. }
  159.  
  160.  
  161. /*    ********************************************************************
  162.     ReadArgs() just reads the command line arguments and sets up the
  163.     screen sizes and such from them.
  164.     ******************************************************************** */
  165.  
  166. void ReadArgs(argc,argv)
  167. int argc;
  168. char **argv;
  169. {
  170.     int count;
  171.     char *dummy = "dummy pointer";
  172.     
  173.     for(count=1;count<argc;count++)
  174.         switch(toupper(argv[count][1]))
  175.             {
  176.                 case 'W':                        /* set width             */
  177.                     cli_screen.Width = (SHORT)atol(&argv[count][2]);
  178.                     break;
  179.                 case 'H':                        /* set height            */
  180.                     cli_screen.Height = (SHORT)atol(&argv[count][2]);
  181.                     break;
  182.                 case 'B':
  183.                     color0 = (UWORD)strtol(&argv[count][2], dummy, 16);
  184.                     break;
  185.                 case 'T':
  186.                     color1 = (UWORD)strtol(&argv[count][2], dummy, 16);
  187.                     break;
  188.             }
  189.     if(cli_screen.Width>384)
  190.         cli_screen.ViewModes |= HIRES;
  191.     if(cli_screen.Height > 240)
  192.         cli_screen.ViewModes |= LACE;
  193.     return;
  194. }
  195.     
  196.     
  197.  
  198. /*     ********************************************************************
  199.     OpenStuff() just sets up all the pointers, libraries, stuff like
  200.     that, for the rest of the program.  It returns TRUE on success or
  201.     FALSE on failure.
  202.      ******************************************************************** */
  203.  
  204. BOOL OpenStuff()
  205. {
  206.     UWORD colorset[2];
  207.     
  208.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  209.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  210.     if((!IntuitionBase) || (!GfxBase))
  211.         return FALSE;
  212.     screen = (struct Screen *)OpenScreen(&cli_screen);
  213.     if(!screen)
  214.         return FALSE;
  215.     close_window.Screen = screen;            /* put window on this screen */
  216.     window = (struct Window *)OpenWindow(&close_window);
  217.     if(!window)
  218.         return FALSE;
  219.     colorset[0] = color0;
  220.     colorset[1] = color1;
  221.     LoadRGB4(ViewPortAddress(window),colorset,2);
  222.     ScreenToFront(screen);                    /* pop it into view */
  223.     return TRUE;
  224. }
  225.  
  226.  
  227. /*     *******************************************************************
  228.     CloseStuff() just closes all the stuff it thinks is open.  But first
  229.     it checks the window list to see if there are other windows out there.
  230.     If there are, it doesn't close anything.  Returns TRUE on successful
  231.     closure, FALSE on error.
  232.     ******************************************************************* */
  233.  
  234. BOOL CloseStuff()
  235. {
  236.     struct Window *win;
  237.     
  238.     win = screen->FirstWindow;
  239.     do                            /* check for visitors */
  240.         {
  241.             if(win != window)
  242.                 return FALSE;
  243.             win = win->NextWindow;
  244.         }
  245.     while(win);
  246.     
  247.     if(window)                    /* nobody here so close up */
  248.         CloseWindow(window);
  249.     if(screen)
  250.         CloseScreen(screen);
  251.     if(IntuitionBase)
  252.         CloseLibrary(IntuitionBase);
  253.     return TRUE;
  254. }
  255.  
  256.  
  257.